/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/${key}/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=10;
    json.url = url ;
    json.param = [
    <#list noCommonFieldList as field>
        {"name": "${field.name}", "value": $.trim($("#${field.name}").val())},
     </#list>   
    ];
    json.columns = [
        {
            "mData": "${key}Code", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEdit${UpperKey}(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='delete${UpperKey}(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
     <#list noCommonFieldList as field>
        {"mData": "${field.name}", "sClass": "text-center"},
     </#list>  
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
<#list noCommonFieldList as field>
	$("#${field.name}").val('');
</#list> 
}

/*删除数据*/
function delete${UpperKey}(${key}Code){
    var _url=getBasePath()+'/mdm/${key}/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var ${key}={};
        ${key}.${key}Code=${key}Code;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(${key}),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除${ZhKey}数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEdit${UpperKey}(${key}Code){
    var _url=getBasePath()+'/mdm/${key}/toEdit.htm?${key}Code='+${key}Code;
    location.href=_url;
}

/*编辑数据*/
function edit${UpperKey}(){
    $validator =$("#${key}_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/${key}/edit.json';
    var ${key}={};
<#list noCommonFieldList as field>
	${key}.${field.name}=$("#${field.name}").val();
</#list> 

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(${key}),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑${ZhKey}数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/* 跳转明细页面*/
function toDetailPage(code){
    var _url=getBasePath()+'/mdm/${key}/detail.htm?${key}Code='+code;
    location.href=_url;
}
/*跳转新增数据页面*/
function toAdd${UpperKey}(){
    var _url=getBasePath()+'/mdm/${key}/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function save${UpperKey}(){
    $validator =$("#${key}_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/${key}/add.json';
    var ${key}={};
<#list noCommonFieldList as field>
	${key}.${field.name}=$("#${field.name}").val();
</#list> 
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(${key}),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增${ZhKey}数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/${key}/list.htm';
}





